package com.osce.basic.controller;

import com.csce.domain.entity.basic.BasicAssetList;
import com.csce.domain.entity.basic.vo.AssetCameraExcel;
import com.csce.domain.entity.basic.vo.AssetMedicalSystemExcel;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.basic.IBasicAssetListService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资产管理Controller
 *
 * @author zzx
 * @since 2023-09-20
 */
@RestController
@RequestMapping("/basic/asset_list")
public class BasicAssetListController extends BaseController {

    @Resource
    private IBasicAssetListService basicAssetListService;

    /**
     * 查询资产管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicAssetList basicAssetList) {
        startPage();
        List<BasicAssetList> list = basicAssetListService.selectBasicAssetListList(basicAssetList);
        return getDataTable(list);
    }

    /**
     * 导出资产管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:export')")
    @Log(title = "资产管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicAssetList basicAssetList) {
        export(response, BasicAssetList.class, basicAssetListService.selectBasicAssetListList(basicAssetList), "资产管理数据");
    }

    /**
     * 导出资产管理模板
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:export')")
    @Log(title = "资产管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export-template/{type}")
    public void exportTemplate(@PathVariable("type") String typeStr, HttpServletResponse response) {
        export(response, "all".equals(typeStr) ? BasicAssetList.class : "camera".equals(typeStr) ? AssetCameraExcel.class : AssetMedicalSystemExcel.class, "资产管理");
    }

    /**
     * 导入资产管理模板
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:import')")
    @Log(title = "资产管理", businessType = BusinessType.EXPORT)
    @PostMapping("/import/{type}")
    public AjaxResult importExcel(@PathVariable("type") String type, MultipartFile file) throws Exception {
        return success(basicAssetListService.importInsertBasicAssetList(new ExcelUtil<>(BasicAssetList.class).importExcel(file.getInputStream()), "all".equals(type) ? 0 : "camera".equals(type) ? 1 : 2));
    }

    /**
     * 获取资产管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicAssetListService.selectBasicAssetListById(id));
    }

    /**
     * 新增资产管理
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:add')")
    @Log(title = "资产管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicAssetList basicAssetList) {
        return toAjax(basicAssetListService.insertBasicAssetList(basicAssetList));
    }

    /**
     * 修改资产管理
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:edit')")
    @Log(title = "资产管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicAssetList basicAssetList) {
        return toAjax(basicAssetListService.updateBasicAssetList(basicAssetList));
    }

    /**
     * 删除资产管理
     */
    @PreAuthorize("@ss.hasPermi('basic:asset_list:remove')")
    @Log(title = "资产管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basicAssetListService.deleteBasicAssetListByIds(ids));
    }
}
